package user03.controller;

import common05.common.Results;
import common05.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import user03.service.TUserService;
import user03.vo.LoginUserVO;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private TUserService tUserService;

    @PostMapping("login")
    public Results login(@RequestBody(required = false) LoginUserVO vo) {
        if (vo == null || StringUtils.isNull(vo.getUsername()) || StringUtils.isNull(vo.getPassword())) {
            return Results.param_error("用户名或密码不能为空");
        }
        return tUserService.login(vo);
    }

    @PostMapping("logout")
    public Results logout(@RequestHeader("userId") Long userId) {
        tUserService.kickUserOff(userId);
        return Results.success();
    }

}
